home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '91 / Hacks '91 / Makin' Copies / Source / Makin Copies.c next >
Encoding:
C/C++ Source or Header  |  1991-06-21  |  7.0 KB  |  285 lines  |  [TEXT/KAHL]

  1. #include <SetUpA4.h>
  2. #include <ShutDown.h>
  3. #include <Timer.h>
  4.  
  5.  
  6. #include "Makin Copies.h"
  7. #include "Makin Other.h"
  8. #include "pStr.h"
  9.  
  10.  
  11. /* in SwapVolume.c */
  12. OSErr SwapVolume(short inVRefNum, long inDirID, short *outVRefNum, long *outDirID);
  13.  
  14.  
  15. void main(void);
  16.  
  17. pascal void Makin_Copies(WindowPtr copy_Window
  18.                 , Str255 window_Name);
  19.  
  20. void Shutting_Down(void);
  21. void Restarting(void);
  22. void Still_Copying(void);
  23.  
  24.  
  25. TMTask        still_Copying_Timer_Task;
  26. unsigned long    setWTitle_Trap_Address;
  27. long            saved_A4;
  28. Handle        handle_To_Ourself;
  29. Handle        snd_MakinCopies;
  30. Handle        snd_Shutdown;
  31. Handle        snd_Throwaway;
  32. Handle        snd_StillMakinCopies;
  33. Handle        snd_Restart;
  34.  
  35. void main(void)
  36.     {
  37.     short            saveVRefNum;
  38.     long            saveDirID;
  39.     short            deadShort;
  40.     long            deadLong;
  41.     SysEnvRec        world;
  42.     OSErr            err;
  43.     char            str[255], str2[255];
  44.     short            file_Reference;
  45.     Handle        hh;
  46.  
  47.     
  48. /*************************************************************/
  49. /*****     setup think c for our embedded globals     ********/
  50. /*************************************************************/
  51.     RememberA0();
  52.     SetUpA4();
  53.     
  54.     
  55. /*************************************************************/
  56. /***** get the handle to our resource and detach it so we ****/
  57. /*****            will stay around after init time        ****/
  58. /*************************************************************/
  59.     asm
  60.         {
  61.         move.l        (sp),saved_A4
  62.         RecoverHandle    SYS
  63.         move.l        a0,handle_To_Ourself
  64.         }
  65.     DetachResource(handle_To_Ourself);
  66.  
  67.  
  68.  
  69. /*************************************************************/
  70. /***** change the finder string to "Makin' Copies:"   ********/
  71. /*************************************************************/
  72.     err = SysEnvirons(1,&world);
  73.     err = SwapVolume(world.sysVRefNum,0,&saveVRefNum,&saveDirID);
  74.  
  75.     file_Reference = OpenResFile((StringPtr)"\pFinder");
  76.     if (ResError() == noErr) 
  77.         {
  78.         hh = Get1Resource('STR#',MAKIN_COPY_STR_LIST);
  79.         
  80.         if ( hh != nil )
  81.             {
  82.             if ( *hh == nil )
  83.                 LoadResource(hh);
  84.             
  85.             HLock(hh);
  86.             
  87.             pStrCpy((char*)str,"\pItems remaining to be copied:");
  88.             pStrCpy((char*)str2,"\pMakin' Copies:");
  89.  
  90.             Munger(hh, 0L, str, str[0]+1, str2, str2[0]+1);
  91.  
  92.             ChangedResource(hh);
  93.             UpdateResFile(file_Reference);
  94.             CloseResFile(file_Reference);
  95.             
  96.             HUnlock(hh);
  97.             }
  98.         }
  99.  
  100.     err = SwapVolume(saveVRefNum,saveDirID,&deadShort,&deadLong);
  101.  
  102.  
  103.  
  104. /*******************************************************************/
  105. /**** load & detach (assume they are not purgable) our sounds   ****/
  106. /*******************************************************************/
  107.     snd_MakinCopies = Get1Resource('snd ',kMakinCopies);
  108.     if ( snd_MakinCopies != 0 )
  109.         {
  110.         if ( *snd_MakinCopies == 0 )
  111.             LoadResource(snd_MakinCopies);
  112.         DetachResource(snd_MakinCopies);
  113.         }
  114.         
  115.     snd_Shutdown = Get1Resource('snd ',kShutdown);
  116.     if ( snd_Shutdown != 0 )
  117.         {
  118.         if ( *snd_Shutdown == 0 )
  119.             LoadResource(snd_Shutdown);
  120.         DetachResource(snd_Shutdown);
  121.         }
  122.         
  123. /*
  124.     snd_Throwaway = Get1Resource('snd ',kThrowaway);
  125.     if ( snd_Throwaway != 0 )
  126.         {
  127.         if ( *snd_Throwaway == 0 )
  128.             LoadResource(snd_Throwaway);
  129.         DetachResource(snd_Throwaway);
  130.         }
  131. */        
  132. /*
  133.     snd_StillMakinCopies = Get1Resource('snd ',kStillMakinCopies);
  134.     if ( snd_StillMakinCopies != 0 )
  135.         {
  136.         if ( *snd_StillMakinCopies == 0 )
  137.             LoadResource(snd_StillMakinCopies);
  138.         DetachResource(snd_StillMakinCopies);
  139.         }
  140. */
  141.         
  142.     snd_Restart = Get1Resource('snd ',kRestart);
  143.     if ( snd_Restart != 0 )
  144.         {
  145.         if ( *snd_Restart == 0 )
  146.             LoadResource(snd_Restart);
  147.         DetachResource(snd_Restart);
  148.         }
  149.  
  150.  
  151. /*******************************************************************/
  152. /********                  patch SetWTitle()                ********/
  153. /*******************************************************************/
  154.     setWTitle_Trap_Address = GetTrapAddress(SETWTITLE_TRAP);
  155.     SetTrapAddress((long)Makin_Copies, SETWTITLE_TRAP);
  156.  
  157.  
  158. /*******************************************************************/
  159. /********  Install the shutdown task to play the sound      ********/
  160. /*******************************************************************/
  161.     ShutDwnInstall((ProcPtr)Shutting_Down, sdOnPowerOff);
  162.  
  163.  
  164. /*******************************************************************/
  165. /********  Install the restart task to play the sound       ********/
  166. /*******************************************************************/
  167.     ShutDwnInstall((ProcPtr)Restarting, sdOnRestart);
  168.  
  169.  
  170. /*******************************************************************/
  171. /********  Install the timer task for still making copies   ********/
  172. /*******************************************************************/
  173.     /*    not working yet
  174.     still_Copying_Timer_Task.tmAddr = (TimerProcPtr)Still_Copying;
  175.     still_Copying_Timer_Task.tmCount = 0;
  176.     still_Copying_Timer_Task.tmWakeUp = 0;
  177.     still_Copying_Timer_Task.tmReserved = 0;
  178.     InsTime((QElemPtr)&still_Copying_Timer_Task);
  179.     */
  180.  
  181. /*******************************************************************/
  182. /********                  we're out of here                ********/
  183. /*******************************************************************/
  184.     RestoreA4();
  185.     } /* void main(void) */
  186.  
  187.  
  188.  
  189.  
  190. pascal void Makin_Copies(copy_Window_Ptr,copy_Window_Name)
  191.  WindowPtr copy_Window_Ptr;
  192.  Str255 copy_Window_Name;
  193.     {
  194.     OSErr        err;
  195.     short        theAddOn;
  196.     Boolean    playThe = FALSE;
  197.     long        theTime;
  198.     
  199.     
  200. /*******************************************************************/
  201. /********               get our globals back                ********/
  202. /*******************************************************************/
  203.     SetUpA4();
  204.     
  205. /*******************************************************************/
  206. /*********  are they setting the window title to "\pCopy"  *********/
  207. /*******************************************************************/
  208.     if (pStrCmp((char *)copy_Window_Name, COPY_STRING, str_equals, 0L, TRUE) == GOOD) {
  209.         PrimeTime((QElemPtr)&still_Copying_Timer_Task, MS_TIME_BEFORE_STILL_COPYING);
  210.         err = SndPlay(0L, snd_MakinCopies, TRUE);
  211.     }
  212.     
  213. /*******************************************************************/
  214. /********              call the original routine            ********/
  215. /*******************************************************************/
  216.     asm
  217.         {
  218.         move.l    setWTitle_Trap_Address,a0
  219.         move.l    copy_Window_Ptr,-(sp)
  220.         move.l    copy_Window_Name,-(sp)
  221.         jsr        (a0)
  222.         }
  223.     
  224.     RestoreA4();
  225.     }
  226.     
  227.  
  228.  
  229. void Shutting_Down(void)
  230.     {
  231.     OSErr        err;
  232.  
  233.     SetUpA4();
  234.     err = SndPlay(0L, snd_Shutdown, FALSE);
  235.     RestoreA4();
  236.  
  237.     }
  238.  
  239.  
  240.  
  241. void Restarting(void)
  242.     {
  243.     OSErr        err;
  244.  
  245.  
  246.     SetUpA4();
  247.     err = SndPlay(0L, snd_Restart, FALSE);
  248.     RestoreA4();
  249.  
  250.     }
  251.  
  252.  
  253.  
  254. /*******************************************************************/
  255. /********      is the copy window still front most        **********/
  256. /*******************************************************************/
  257. void Still_Copying(void)
  258. {
  259.     OSErr        err;
  260.     Str255    window_Title;
  261.     WindowPtr    front_Window;
  262.     
  263.     
  264.     asm {
  265.         movem.l    d0-d7/a0-a6, -(sp)
  266.     }
  267.     
  268.     SetUpA4();
  269.  
  270.  
  271. /***********
  272.     front_Window = FrontWindow();
  273.  
  274.     GetWTitle(front_Window, window_Title);
  275.     
  276.     if (pStrCmp((char *)window_Title, COPY_STRING, str_equals, 0L, TRUE) == GOOD)
  277.         err = SndPlay(0L, snd_StillMakinCopies, TRUE);
  278. *****************/
  279.     RestoreA4();
  280.     
  281.     asm {
  282.         movem.l    (sp)+, d0-d7/a0-a6
  283.     }
  284. }
  285.